<?php
/*********************/
/*                   */
/*  enjoying7       */
/*   订单里cps       */
/*    2009-8-22      */
/*                   */
/*********************/

class cct_order extends ctl_order
{

	var $noCache = true;

	function index( $order_id, $selecttype = false )
	{
		if ( $_COOKIE['ST_ShopEx-Order-Buy'] != md5( $this->system->getconf( "certificate.token" ).$order_id ) )
		{
			$this->splash( "failed", "index.php", __( "订单无效！" ) );
		}
		$objOrder = $this->system->loadmodel( "trading/order" );
		$aOrder = $objOrder->load( $order_id );
		$aOrder['member_id'] = is_null( $aOrder['member_id'] ) ? false : $aOrder['member_id'];
		$this->_verifymember( $aOrder['member_id'] );
		$aOrder['cur_money'] = ( $aOrder['amount']['total'] - $aOrder['amount']['payed'] ) * $aOrder['cur_rate'];
		
		if ( $selecttype )
		{
			$selecttype = 1;
			$payment = $this->system->loadmodel( "trading/payment" );
			$payments = $payment->getbycur( $this->pagedata['order']['currency'] );
			foreach ( $payments as $key => $val )
			{
				$payments[$key]['money'] = $objOrder->chgpayment( $order_id, $val['id'], $aOrder['amount']['total'] - $aOrder['amount']['payed'], 1 );
			}
			$payment = $this->system->loadmodel( "trading/payment" );
			$payment->showpayextendcon( $payments, $aOrder['pay_extend'] );
			$this->pagedata['payments'] = $payments;
		}
		else
		{
			$selecttype = 0;
		}
		$this->pagedata['order']['selecttype'] = $selecttype;
		$this->pagedata['order']['paytype'] = strtoupper( $this->pagedata['order']['paytype'] );
		$objCur = $this->system->loadmodel( "system/cur" );
		$aCur = $objCur->getdefault( );
		$this->pagedata['order']['cur_def'] = $aCur['cur_code'];
		$payment = $this->system->loadmodel( "trading/payment" );
		$payment->ordmemextend( $aOrder, $extendInfo );
		if ( $extendInfo )
		{
			$this->pagedata['extendInfo'] = $extendInfo;
		}
		//更新订单等级和积分
		/*$data = array();
		$data['order_id']=$order_id;
		$data['member_lv_id']=$GLOBALS['runtime']['member_lv'];
		if($data['member_lv_id']>=4)$data['score_g']=0 ;
		else $data['score_g'] = intval( $aOrder['amount']['final']-$aOrder['shipping']['cost'] );
		//d1优尚 10元运费
		if(($aOrder['member_id'] == 6318) && intval($aOrder['shipping']['cost'])!=10)
		{
			$diff = 10-$aOrder['shipping']['cost'];
			$data['cost_freight'] = $aOrder['shipping']['cost'] + $diff ;
			$data['total_amount'] = $aOrder['amount']['total'] + $diff ;
			$data['final_amount'] = $aOrder['amount']['final'] + $diff ;
			$aOrder['shipping']['cost'] = 10;
			$aOrder['amount']['total'] = $data['total_amount'];
		}
		if($objOrder->setshipstatus($data)){}
		
		*/
		//cps start
		$cpstotal = $aOrder['amount']['final'] - $aOrder['shipping']['cost'];
		$cps_percent = $cpstotal * 0.15;
		$adout="";
		getrefer($refer);
		if($refer['refer_id']){
			$referinfo = explode("|",$refer['refer_id']);
			
			if($referinfo[0]=='ptubao' && $GLOBALS['runtime']['member_lv'] < 4){
			$adout .= "<script src=\"http://www.itubao.com/gather/orderpush.php?od=".date("YmdHis",$aOrder['createtime'])."&uid=".$aOrder['member_id']."&oid=".$aOrder['order_id']."&pid=".$aOrder['order_id']."&tbid=".$referinfo[1]."&pn=1&p=".$cpstotal."&os=0&aoid=domofs&poid=1\"></script>";
			
			}
			elseif($referinfo[0]=='pfanhuan' && $GLOBALS['runtime']['member_lv'] < 4){
			$adout .= "<script src=\"http://service.fanhuan.com/receiveorder.asp?a_id=domofs&a_name=domofs&u_id=".$referinfo[1]."&o_id=".$aOrder['order_id']."&p_id=".$aOrder['order_id']."&p_cnt=1&p_price=".$cpstotal."&f_money=".$cps_percent."\"></script>";
			
			}
		
		
		}
		$this->pagedata['adout'] = $adout;
		//cps end
		
		$this->pagedata['order'] = $aOrder;
		if ( !$this->pagedata['order'] )
		{
			$this->system->error( 404 );
			exit( );
		}
		$this->output( );
	}
	
	
	

}

?>